%% Summarize beta parameters


clear
cd ../china/data
load hs10_indlist.raw;
indN=length(hs10_indlist);

industry=0;
beta_full=zeros(1,4);
importers=0;
exporters=0;

for w=1:50

folder=sprintf('../china/estimation/hs10/biggest/raw_%d',hs10_indlist(w,1))



cd (folder)

load imp.raw;
load data2_q_biggest.mat
load beta_newq_biggest.mat;
%load beta_newq.mat;

M=length(imp);

beta_full=[beta_full; beta_p_sol beta_x_sol beta_c_sol xi_tilde_sol];
industry=[industry; hs10_indlist(w,1)];
importers=[importers; M];
exporters=[exporters; X];
end

industry=industry(2:end,:);
beta_full=beta_full(2:end,:);
importers=importers(2:end,:);
exporters=exporters(2:end,:);


summary=[importers exporters];

load ../china/data/trade_share.raw; 
trade_share=trade_share(1:w,:);
trade_share=trade_share/sum(trade_share);
trade_share=repmat(trade_share,1,4);
beta_full_weighted=beta_full.*trade_share;
beta_full_weighted=sum(beta_full_weighted,1);
b1=mean(beta_full)
b2=median(beta_full)
b3=beta_full_weighted

beta_summary=[b1; b2; b3];